<?php
/**
 *
 */

namespace Beike\Repositories;

use Beike\Models\Order;
use Beike\Models\OrderLog;
use Beike\Models\OrderProduct;
use Beike\Services\StateMachineService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

class OrderLogRepo
{
    public static function createLogs($data)
    {
        $orderLogs = [];
        $model = new OrderLog();
        foreach ($data as $value) {
//            $model->fill($orderLogs);
//            $model->saveOrFail();
            $one_log = [
                'key_id'        => $value['key_id'],
                'type'          => $value['type']??'order',
                'update_field'  => $value['update_field']??'price',
                'old_value'     => $value['old_value'],
                'new_value'     => $value['new_value'],
                'remark'        => $value['remark']??$value['old_value']. '-->>' .$value['new_value'],
            ];
            OrderLog::query()->create($one_log);
        }
//        OrderLog::query()->create($orderLogs);
//        $region->fill([
//            'name'        => $data['name'],
//            'description' => $data['description'],
//        ]);
    }

    /**
     * 查找单条记录
     */
    public static function find($id)
    {
        return OrderLog::query()->findOrFail($id);
    }
}
